﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.IO;
using System.Data;

namespace EasyCheque.Cheque
{
    public partial class QueryCheque : System.Web.UI.Page
    {
        public Stream CQFileStream;

        protected void Page_Load(object sender, EventArgs e)
        {
            Image_ChequeImage.Visible = false;
            TextBox_STATE.Text = "请先加载支票文件。";
        }

        protected void LoadCheque(object sender, EventArgs e)
        {
            Image_ChequeImage.Visible = false;
            TextBox_STATE.Visible = true;
            if (FileUpload_ChequeFile.HasFile)
            {
                TextBox_STATE.ForeColor = System.Drawing.Color.Green;
                TextBox_STATE.Text = "该支票可以使用。";
                Image_ChequeImage.Visible = true;
                CQFileStream = FileUpload_ChequeFile.FileContent;
                Logic.Cheque cf = new Logic.Cheque(CQFileStream);
                int ChequeState = cf.Verify();
                if (ChequeState == -1)
                {
                    TextBox_STATE.ForeColor = System.Drawing.Color.Red;
                    TextBox_STATE.Text = "支票文件验证失败";
                    Image_ChequeImage.Visible = false;
                }
                else if (ChequeState == 1)
                {
                    TextBox_STATE.ForeColor = System.Drawing.Color.Red;

                    TextBox_STATE.Text = "该支票已经使用";
                }
                else if (ChequeState == 2)
                {
                    TextBox_STATE.ForeColor = System.Drawing.Color.Red;

                    TextBox_STATE.Text = "该支票已经注销";
                }
                Session["ChequeFileStream"] = CQFileStream;
                Image_ChequeImage.ImageUrl = "ChequeFileImg.aspx";
                return;
            }
            Image_ChequeImage.Visible = false;
            Label_LoadMessage.Text = "请选择支票文件";
        }

    }
}
